package top.i51213.fastaction.action.print;

import android.content.Context;
import android.print.PrintManager;
import android.view.View;

import top.i51213.fastaction.R;
import top.i51213.fastaction.action.BaseActonComponent;
import top.i51213.fastaction.action.Data;
import top.i51213.fastaction.action.DataType;
import top.i51213.fastaction.action.IntentType;
import top.i51213.fastaction.action.SameLast;
import top.i51213.fastaction.util.IOUtil;

public class PrintActionComponent extends BaseActonComponent implements SameLast {
    public PrintActionComponent(Context context) {
        super(context);
    }

    @Override
    public int getImageResId() {
        return R.mipmap.print;
    }

    @Override
    public String getTitle() {
        return "打印";
    }

    @Override
    public String getInfo() {
        return "";
    }

    @Override
    public View getEditView() {
        return null;
    }

    @Override
    public void editViewDismissListener() {

    }

    private String getTaskName() {
        return IOUtil.getTimeString();
    }

    @Override
    protected Data makeOutputData() {
        PrintManager printManager = (PrintManager) getContext().getSystemService(Context.PRINT_SERVICE);
        // Set job name, which will be displayed in the print queue
        String taskName = getTaskName();
        String jobName = getContext().getString(R.string.app_name) + " Document-" + taskName;
        // Start a print job, passing in a PrintDocumentAdapter implementation
        // to handle the generation of a print document
        Data data=getInputData();
        if(data.getDataType()==DataType.IMAGE){
            printManager.print(jobName, new ImagePrintDocumentAdapter(getContext(), getInputData().getUris(), taskName), null); //
        }else if(data.getDataType()==DataType.PdfFile){
            printManager.print(jobName, new PdfPrintDocumentAdapter(getContext(), getInputData().getUris(), taskName), null); //
        }
        return null;
    }

    @Override
    public IntentType getCurrentIntentType() {
        return IntentType.Print;
    }

    @Override
    public DataType getOutputDataType() {
        return DataType.PdfFile;
    }
}
